﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace OgilvyOne.SqlServerDAL
{
    public class DAlArticleInfo: OgilvyOne.IDAL.IDALArticleInfo
    {
        public int getScalar(string sql)
        {           //sql语句的参数 如"insert into golf_Graffiti (pic,title,author) VALUES('qbfiqb','2222','3333');SELECT @@IDENTITY"
            return Convert.ToInt32(SQLHelper.ExecuteScalar(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, sql, new SqlParameter[0]).ToString());
        }

        public DataTable query(string sql)
        {
            DataSet data = new DataSet();
            using (SqlDataAdapter dsCommand = new SqlDataAdapter())
            {
                try
                {
                    dsCommand.SelectCommand = new SqlCommand();
                    dsCommand.SelectCommand.CommandText = sql;
                    dsCommand.SelectCommand.Connection = new SqlConnection(SQLHelper.CONN_STRING_NON_DTC);
                    dsCommand.Fill(data);
                }
                catch (SqlException err)
                {
                    System.Console.WriteLine(err.Message);
                }
            }
            return data.Tables[0];
        }

        public int select(string sql)
        {
            return Convert.ToInt32(SQLHelper.ExecuteScalar(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, sql, new SqlParameter[0]).ToString());
        }

        public int insert(string sql, params SqlParameter[] paramList)
        {
            return SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, sql, paramList);
        }
    }
}
